using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;
using System.Windows.Forms;
using System.Xml.Serialization;
using OpenComposite.Base.Collections;
using OpenComposite.Workflow.Extenders;

namespace OpenComposite.EII.Repository
{
	public partial class Workflow
	{
		#region Interface
		private WorkflowInterface _wfInterface = null;
		/// <summary>
		/// Gets the workflow interface.
		/// </summary>
		/// <value>The interface.</value>
		public WorkflowInterface Interface
		{
			get
			{
				if ( _wfInterface == null )
					_wfInterface = new WorkflowInterface(this);
				return _wfInterface;
			}
		}
		#endregion

		#region Class: WorkflowInterface
		[Serializable, TypeConverter(typeof(ExpandableObjectConverter))]
		public class WorkflowInterface//: IComponent
		{
			#region Initialization
			/// <summary>
			/// Initializes a new instance of the <see cref="WorkflowInterface"/> class.
			/// </summary>
			/// <param name="workflow">The workflow.</param>
			internal WorkflowInterface(Workflow workflow)
			{
				//this.Site = new Designer.DesignerSite(workflow, workflow, null);
				_wfmethods = new WorkflowMethodCollection();
				_wfevents = new WorkflowEventCollection();
				_wffields = new WorkflowFieldCollection();

				if ( workflow.ID > 0 ) {
					_wfmethods.AddRange(Global.Data.GetWorkflowMethods(workflow.ID));
					_wfevents.AddRange(Global.Data.GetWorkflowEvents(workflow.ID));
					_wffields.AddRange(Global.Data.GetWorkflowFields(workflow.ID));
				}
			}
			#endregion

			#region Public Members
			/// <summary>
			/// Gets the workflow methods.
			/// </summary>
			/// <value>The methods.</value>
			public WorkflowMethodCollection Methods
			{
				get { return _wfmethods; }
			}
			/// <summary>
			/// Gets the workflow events.
			/// </summary>
			/// <value>The events.</value>
			public WorkflowEventCollection Events
			{
				get { return _wfevents; }
			}
			/// <summary>
			/// Gets the workflow fields.
			/// </summary>
			/// <value>The fields.</value>
			public WorkflowFieldCollection Fields
			{
				get { return _wffields; }
			}
			#endregion

			#region Private Members

			#region Fields
			private WorkflowMethodCollection _wfmethods;
			private WorkflowEventCollection _wfevents;
			private WorkflowFieldCollection _wffields;
			#endregion

			#endregion
		}
		#endregion
	}

	#region Workflow Method Classes

	#region Class: WorkflowMethodCollection
	public class WorkflowMethodCollection : BindingListEx<WorkflowMethod>
	{
		/// <summary>
		/// Removes all elements from the collection.
		/// </summary>
		protected override void ClearItems()
		{
			foreach ( WorkflowMethod item in this.Items ) {
				item.Delete(false);
			}
			base.ClearItems();
		}
		/// <summary>
		/// Removes the item at the specified index.
		/// </summary>
		/// <param name="index">The zero-based index of the item to remove.</param>
		/// <exception cref="T:System.NotSupportedException">
		/// You are removing a newly added item and <see cref="P:System.ComponentModel.IBindingList.AllowRemove"/> is set to false.
		/// </exception>
		protected override void RemoveItem(int index)
		{
			this.Items[index].Delete(false);
			base.RemoveItem(index);
		}
		/// <summary>
		/// Replaces the item at the specified index with the specified item.
		/// </summary>
		/// <param name="index">The zero-based index of the item to replace.</param>
		/// <param name="item">The new value for the item at the specified index. The value can be null for reference types.</param>
		/// <exception cref="T:System.ArgumentOutOfRangeException">
		/// 	<paramref name="index"/> is less than zero.
		/// -or-
		/// <paramref name="index"/> is greater than <see cref="P:System.Collections.ObjectModel.Collection`1.Count"/>.
		/// </exception>
		protected override void SetItem(int index, WorkflowMethod item)
		{
			this.Items[index].Delete(false);
			base.SetItem(index, item);
		}
	}
	#endregion

	#region Class: WorkflowMethod
	[RepositoryItem(ItemType.Workflow_Method, "wf_methods", "wf_method_id")]
	public class WorkflowMethod : RepositoryItemBaseEx, IWorkflowInterfaceItem, IEquatable<WorkflowMethod>
	{
		#region Initialization
		/// <summary>
		/// Initializes a new instance of the <see cref="WorkflowMethod"/> class.
		/// </summary>
		/// <param name="serviceProvider">The service provider.</param>
		/// <param name="bCreateNew">if set to <c>true</c> [b create new].</param>
		public WorkflowMethod(IServiceProvider serviceProvider, bool bCreateNew)
			: base("wf_method_id", "wf_method_nm", "wf_method_desc", "wf_method_ntext", "<New Method>")
		{
			if ( bCreateNew )
				this.CreateNew();

			InitializeServiceProvider(serviceProvider);
		}
		#endregion

		#region RepositoryItemBase Members
		/// <summary>
		/// Gets the image key.
		/// </summary>
		/// <value>The image key.</value>
		public override string ImageKey
		{
			get { return "method"; }
		}

		/// <summary>
		/// Gets the selected image key.
		/// </summary>
		/// <value>The selected image key.</value>
		public override string SelectedImageKey
		{
			get { return "method"; }
		}

		/// <summary>
		/// Gets the image.
		/// </summary>
		/// <value>The image.</value>
		public override System.Drawing.Image Image
		{
			get { return OpenComposite.Repository.Properties.Resources.method; }
		}

		/// <summary>
		/// Gets the selected image.
		/// </summary>
		/// <value>The selected image.</value>
		public override System.Drawing.Image SelectedImage
		{
			get { return OpenComposite.Repository.Properties.Resources.method; }
		}

		/// <summary>
		/// Gets the type of the repository item.
		/// </summary>
		/// <value>The type of the repository item.</value>
		public override ItemType RepositoryItemType
		{
			get { return ItemType.Workflow_Method; }
		}

		/// <summary>
		/// Gets the name of the repository item type.
		/// </summary>
		/// <value>The name of the repository item type.</value>
		public override string RepositoryItemTypeName
		{
			get { return "Workflow Method"; }
		}

		/// <summary>
		/// Gets the repository item type description.
		/// </summary>
		/// <value>The repository item type description.</value>
		public override string RepositoryItemTypeDescription
		{
			get { return ""; }
		}

		/// <summary>
		/// Gets the name of the table.
		/// </summary>
		/// <value>The name of the table.</value>
		public override string TableName
		{
			get { return "wf_methods"; }
		}

		/// <summary>
		/// Gets the allowed child types.
		/// </summary>
		/// <value>The allowed child types.</value>
		public override List<ItemType> AllowedChildTypes
		{
			get { return null; }
		}

		/// <summary>
		/// Gets the icon.
		/// </summary>
		/// <returns></returns>
		public override System.Drawing.Icon GetIcon()
		{
			Bitmap bmp = new Bitmap(this.Image);
			bmp.MakeTransparent(Color.Magenta);
			return Icon.FromHandle(bmp.GetHicon());
		}

		/// <summary>
		/// Internally delete the item.
		/// </summary>
		/// <returns></returns>
		internal override bool DeleteInternal()
		{
			return base.DeleteInternal();
		}

		/// <summary>
		/// Internal delete the item from the database.
		/// </summary>
		/// <param name="bAsk">if set to <c>true</c> [b ask].</param>
		/// <returns></returns>
		internal override bool DeleteFromDBInternal(bool bAsk)
		{
			return base.DeleteFromDBInternal(bAsk);
		}
		#endregion

		#region Public Members

		#region Properties

		#region Input Business Object
		/// <summary>
		/// Gets or sets the input business object ID.
		/// </summary>
		/// <value>The input business object ID.</value>
		public int InputBusinessObjectID
		{
			get { return getInt("wf_method_input_bobj_id", -1); }
			set { setValue("InputBusinessObjectID", "wf_method_input_bobj_id", value); }
		}
		/// <summary>
		/// Gets or sets the input business object.
		/// </summary>
		/// <value>The input business object.</value>
		public BusinessObject InputBusinessObject
		{
			get { return this.RepositoryService.GetItem<BusinessObject>(this.InputBusinessObjectID); }
			set
			{
				if ( value != null )
					this.InputBusinessObjectID = value.ID;
				else
					this.InputBusinessObjectID = -1;
			}
		}
		/// <summary>
		/// Gets the name of the input business object.
		/// </summary>
		/// <value>The name of the input business object.</value>
		public string InputBusinessObjectName
		{
			get
			{
				BusinessObject bo = this.InputBusinessObject;
				return ( bo == null ? "" : bo.Name );
			}
		}
		#endregion

		#region Output Business Object
		/// <summary>
		/// Gets or sets the output business object ID.
		/// </summary>
		/// <value>The output business object ID.</value>
		public int OutputBusinessObjectID
		{
			get { return getInt("wf_method_output_bobj_id", -1); }
			set { setValue("OutputBusinessObjectID", "wf_method_output_bobj_id", value); }
		}
		/// <summary>
		/// Gets or sets the output business object.
		/// </summary>
		/// <value>The output business object.</value>
		public BusinessObject OutputBusinessObject
		{
			get { return this.RepositoryService.GetItem<BusinessObject>(this.OutputBusinessObjectID); }
			set
			{
				if ( value != null )
					this.OutputBusinessObjectID = value.ID;
				else
					this.OutputBusinessObjectID = -1;
			}
		}
		/// <summary>
		/// Gets the name of the output business object.
		/// </summary>
		/// <value>The name of the output business object.</value>
		public string OutputBusinessObjectName
		{
			get
			{
				BusinessObject bo = this.OutputBusinessObject;
				return ( bo == null ? "" : bo.Name );
			}
		}
		#endregion

		#region Workflow
		/// <summary>
		/// Gets or sets the workflow ID.
		/// </summary>
		/// <value>The workflow ID.</value>
		public int WorkflowID
		{
			get { return getInt("workflow_id", -1); }
			set { setValue("WorkflowID", "workflow_id", value); }
		}
		/// <summary>
		/// Gets or sets the workflow.
		/// </summary>
		/// <value>The workflow.</value>
		public Workflow Workflow
		{
			get
			{
				if ( this.WorkflowID > 0 ) {
					return this.RepositoryService.GetItem<OpenComposite.EII.Repository.Workflow>(this.WorkflowID);
				} else {
					return null;
				}
			}
			set { this.WorkflowID = ( value == null ? -1 : value.ID ); }
		}
		#endregion

		#region Mashup Control
		private Workflow.MashupControl _mashupCtrl = null;
		/// <summary>
		/// Gets or sets the mashup control.
		/// </summary>
		/// <value>The mashup control.</value>
		public Workflow.MashupControl MashupControl
		{
			get
			{
				if ( _mashupCtrl == null ) {
					_mashupCtrl = getXmlSerializedObject<Workflow.MashupControl>("wf_method_ntext");
				}
				return _mashupCtrl;
			}
			set
			{
				_mashupCtrl = value;
				setXmlSerializedObject("MashupControl", "wf_method_ntext", value);
			}
		}
		#endregion

		#region ExtendedProperties
		private WFMethodProperties _properties = null;
		/// <summary>
		/// Gets the extended properties.
		/// </summary>
		/// <value>The extended properties.</value>
		public WFMethodProperties ExtendedProperties
		{
			get
			{
				if ( _properties == null ) {
					_properties = getXmlSerializedObject<WFMethodProperties>("wf_method_properties");
					if ( _properties == null )
						_properties = new WFMethodProperties();
				}
				return _properties;
			}
		}
		#endregion

		#region Properties for Databinding
		/// <summary>
		/// Gets a value indicating whether this instance is initialize correlation.
		/// </summary>
		/// <value>
		/// 	<c>true</c> if this instance is initialize correlation; otherwise, <c>false</c>.
		/// </value>
		public bool IsInitializeCorrelation
		{
			get { return this.ExtendedProperties.IsInitializeCorrelation; }
		}
		/// <summary>
		/// Gets the correlation aliases string.
		/// </summary>
		/// <value>The correlation aliases string.</value>
		public string CorrelationAliasesString
		{
			get { return this.ExtendedProperties.CorrelationAliasesString; }
		}
		#endregion

		#endregion

		#region Methods

		/// <summary>
		/// Sets the drag drop data object.
		/// </summary>
		/// <param name="dataObj">The data object.</param>
		public override void SetDragDropDataObject(IDataObject dataObj)
		{
			base.SetDragDropDataObject(dataObj);

			ToolboxItem ti = OpenComposite.EII.Designer.Workflow.ToolboxService.GetToolboxItem(
								typeof(OpenComposite.Workflow.LogicalMethodCallActivity));
			OpenComposite.Workflow.LogicalMethodCallActivityToolboxItem ati = ti as OpenComposite.Workflow.LogicalMethodCallActivityToolboxItem;
			if ( ati != null ) {
				ati.InitializeLogicalMethodCallActivity +=
					new EventHandler<OpenComposite.Workflow.InitializeLogicalMethodCallActivityEventArgs>(
						this.ati_InitializeLogicalMethodCallActivity);
			}
			dataObj.SetData(typeof(ToolboxItem), ti);
		}

		private void ati_InitializeLogicalMethodCallActivity(object sender,
			OpenComposite.Workflow.InitializeLogicalMethodCallActivityEventArgs e)
		{
			OpenComposite.Workflow.LogicalMethodCallActivityToolboxItem ati = sender as OpenComposite.Workflow.LogicalMethodCallActivityToolboxItem;
			if ( e.LogicalMethodCallActivity != null ) {
				OpenComposite.EII.Designer.Workflow.WorkflowLoader wfl = null;
				if ( e.LogicalMethodCallActivity.Site != null ) {
					wfl = e.LogicalMethodCallActivity.Site.GetService(typeof(System.Workflow.ComponentModel.Design.WorkflowDesignerLoader)) as OpenComposite.EII.Designer.Workflow.WorkflowLoader;
				}
				LogicalActivity logact;
				if ( e.LogicalMethodCallActivity.LogicalActivityId == 0 && ati.Tag is int )
					logact = this.AssignLogicalActivity((int)ati.Tag);
				else
					logact = this.AssignLogicalActivity(e.LogicalMethodCallActivity.LogicalActivityId);
				e.LogicalMethodCallActivity.LogicalActivityId = logact.ID;
				e.LogicalMethodCallActivity.LogicalActivityName = logact.Name;

				logact.LogicalActivityType = LogicalActivityType.LogicalMethodCall;

				e.LogicalMethodCallActivity.HasOutputObject = ( this.OutputBusinessObject != null );
				if ( this.OutputBusinessObject != null ) {
					e.LogicalMethodCallActivity.SetValue(OutputVariableNameExtenderProvider.OutputVarNameProperty,
						string.Format("{0}_{1}", this.Name, this.OutputBusinessObjectName));
				}

				Helpers.SetActivityProperty(e.LogicalMethodCallActivity, "Name", logact.Name);
				Helpers.SetActivityProperty(e.LogicalMethodCallActivity, "Text", logact.Name);
				if ( wfl != null ) {
					Helpers.SetActivityProperty(e.LogicalMethodCallActivity, "InterfaceType", wfl.ExternalDataExchangeInterfaceType);
					Helpers.SetActivityProperty(e.LogicalMethodCallActivity, "MethodName", this.Name);
				}
				if ( ati != null ) {
					ati.Tag = logact.ID;
				}
			}
		}

		/// <summary>
		/// Gets the assigned logical activities.
		/// </summary>
		/// <returns></returns>
		public BindingListEx<LogicalActivity> GetAssignedLogicalActivities()
		{
			return Global.Data.GetLogicalActivitiesByWorkflowMethod(this.ID);
		}
		/// <summary>
		/// Assigns the logical activity.
		/// </summary>
		/// <param name="idLogicalActivity">The id logical activity.</param>
		/// <returns></returns>
		public LogicalActivity AssignLogicalActivity(int idLogicalActivity)
		{
			RepositoryService repSvc = (RepositoryService)this.GetService(typeof(RepositoryService));
			if ( repSvc == null )
				throw new NullReferenceException("RepositoryService not available.");

			bool bSC;
			LogicalActivity logact = null;
			if ( idLogicalActivity > 0 ) {
				logact = repSvc.GetItem(ItemType.LogicalActivity, idLogicalActivity, true) as LogicalActivity;
				if ( logact.WorkflowMethodID != this.ID ) {
					setLogActValues(logact);
				}
			} else {
				logact = repSvc.GetItem(ItemType.LogicalActivity, true,
					Global.Status.CurrentRepositoryId, false, false, out bSC) as LogicalActivity;
				setLogActValues(logact);
			}
			return logact;
		}
		private void setLogActValues(LogicalActivity logact)
		{
			logact.BeginEdit();
			try {
				logact.WorkflowMethodID = this.ID;
				logact.Name = this.Name;
				logact.Description = this.Description;
				logact.NText = this.NText;
				logact.LogicalActivityType = LogicalActivityType.LogicalMethodCall;
			} finally {
				logact.EndEdit(true);
			}
		}

		/// <summary>
		/// Saves this instance.
		/// </summary>
		/// <returns></returns>
		public override bool Save()
		{
			if ( _properties != null ) {
				setXmlSerializedObject("ExtendedProperties", "wf_method_properties", _properties);
			}
			return base.Save();
		}
		/// <summary>
		/// Deletes this instance.
		/// </summary>
		/// <param name="bAsk">if set to <c>true</c> show a message to ask for deleting.</param>
		/// <returns></returns>
		public override bool Delete(bool bAsk)
		{
			if ( !bAsk || MessageBox.Show(this.DeleteQuestion, this.RepositoryItemType.ToString(),
				 MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes ) {
				BindingListEx<LogicalActivity> logacts = this.GetAssignedLogicalActivities();
				foreach ( LogicalActivity la in logacts ) {
					la.BeginEdit();
					la.WorkflowMethodID = -1;
					la.EndEdit(true);
					la.Delete(false);
				}
				return base.Delete(false);
			} else {
				return false;
			}
		}

		/// <summary>
		/// Copies this instance.
		/// </summary>
		/// <param name="deep"><c>true</c> to recursively copy the item and all subitems;
		/// <c>false</c> to copy only the item itself.</param>
		/// <returns>The copied item.</returns>
		public override IRepositoryItem Copy(bool deep)
		{
			WorkflowMethod copy = new WorkflowMethod(this, true);
			this.CopyDataRowToTarget(copy);
			return copy;
		}
		/// <summary>
		/// Copies this instance.
		/// </summary>
		/// <param name="deep">if set to <c>true</c> creates a deep copy.</param>
		/// <param name="createCopyOfName">if set to <c>true</c> the name of the new item starts with "CopyOf".</param>
		/// <returns>A copy of this instance</returns>
		internal WorkflowMethod CopyInternal(bool deep, bool createCopyOfName)
		{
			WorkflowMethod copy = new WorkflowMethod(this, true);
			this.CopyDataRowToTarget(copy, createCopyOfName);
			return copy;
		}

		#endregion

		#endregion

		#region IWorkflowInterfaceItem Members

		/// <summary>
		/// Gets the IO types.
		/// </summary>
		/// <value>The IO types.</value>
		public string IOTypes
		{
			get
			{
				string input = this.InputBusinessObjectName;
				string output = this.OutputBusinessObjectName;
				if ( string.IsNullOrEmpty(output) ) output = "void";
				return string.Format("{0} ( {1} )", output, input);
			}
		}

		/// <summary>
		/// Gets the summary.
		/// </summary>
		/// <value>The summary.</value>
		public string Summary
		{
			get { return this.Description.Replace(Environment.NewLine, ""); }
		}

		#endregion

		#region Class: WFMethodProperties
		public class WFMethodProperties : WorkflowInterfaceItemProperties
		{
		}
		#endregion

		#region IEquatable<WorkflowMethod> Members

		/// <summary>
		/// Indicates whether the current object is equal to another object of the same type.
		/// </summary>
		/// <param name="other">An object to compare with this object.</param>
		/// <returns>
		/// true if the current object is equal to the <paramref name="other"/> parameter; otherwise, false.
		/// </returns>
		public bool Equals(WorkflowMethod other)
		{
			if ( other == null ) return false;
			if ( other.ID == this.ID ) return true;
			return false;
		}

		#endregion
	}
	#endregion

	#endregion

	#region Workflow Event Classes

	#region Class: WorkflowEventCollection
	public class WorkflowEventCollection : BindingListEx<WorkflowEvent>
	{
		/// <summary>
		/// Removes all elements from the collection.
		/// </summary>
		protected override void ClearItems()
		{
			foreach ( WorkflowEvent item in this.Items ) {
				item.Delete(false);
			}
			base.ClearItems();
		}
		/// <summary>
		/// Removes the item at the specified index.
		/// </summary>
		/// <param name="index">The zero-based index of the item to remove.</param>
		/// <exception cref="T:System.NotSupportedException">
		/// You are removing a newly added item and <see cref="P:System.ComponentModel.IBindingList.AllowRemove"/> is set to false.
		/// </exception>
		protected override void RemoveItem(int index)
		{
			this.Items[index].Delete(false);
			base.RemoveItem(index);
		}
		/// <summary>
		/// Replaces the item at the specified index with the specified item.
		/// </summary>
		/// <param name="index">The zero-based index of the item to replace.</param>
		/// <param name="item">The new value for the item at the specified index. The value can be null for reference types.</param>
		/// <exception cref="T:System.ArgumentOutOfRangeException">
		/// 	<paramref name="index"/> is less than zero.
		/// -or-
		/// <paramref name="index"/> is greater than <see cref="P:System.Collections.ObjectModel.Collection`1.Count"/>.
		/// </exception>
		protected override void SetItem(int index, WorkflowEvent item)
		{
			this.Items[index].Delete(false);
			base.SetItem(index, item);
		}
	}
	#endregion

	#region Class: WorkflowEvent
	[RepositoryItem(ItemType.Workflow_Event, "wf_events", "wf_event_id")]
	public class WorkflowEvent : RepositoryItemBaseEx, IWorkflowInterfaceItem, IEquatable<WorkflowEvent>
	{
		#region Initialization
		/// <summary>
		/// Initializes a new instance of the <see cref="WorkflowEvent"/> class.
		/// </summary>
		/// <param name="serviceProvider">The service provider.</param>
		/// <param name="bCreateNew">if set to <c>true</c> [b create new].</param>
		public WorkflowEvent(IServiceProvider serviceProvider, bool bCreateNew)
			: base("wf_event_id", "wf_event_nm", "wf_event_desc", "wf_event_ntext", "<New Event>")
		{
			if ( bCreateNew )
				this.CreateNew();

			InitializeServiceProvider(serviceProvider);
		}
		#endregion

		#region RepositoryItemBase Members
		/// <summary>
		/// Gets the image key.
		/// </summary>
		/// <value>The image key.</value>
		public override string ImageKey
		{
			get { return "event"; }
		}

		/// <summary>
		/// Gets the selected image key.
		/// </summary>
		/// <value>The selected image key.</value>
		public override string SelectedImageKey
		{
			get { return "event"; }
		}

		/// <summary>
		/// Gets the image.
		/// </summary>
		/// <value>The image.</value>
		public override System.Drawing.Image Image
		{
			get { return OpenComposite.Repository.Properties.Resources.png_event; }
		}

		/// <summary>
		/// Gets the selected image.
		/// </summary>
		/// <value>The selected image.</value>
		public override System.Drawing.Image SelectedImage
		{
			get { return this.Image; }
		}

		/// <summary>
		/// Gets the type of the repository item.
		/// </summary>
		/// <value>The type of the repository item.</value>
		public override ItemType RepositoryItemType
		{
			get { return ItemType.Workflow_Event; }
		}

		/// <summary>
		/// Gets the name of the repository item type.
		/// </summary>
		/// <value>The name of the repository item type.</value>
		public override string RepositoryItemTypeName
		{
			get { return "Workflow Event"; }
		}

		/// <summary>
		/// Gets the repository item type description.
		/// </summary>
		/// <value>The repository item type description.</value>
		public override string RepositoryItemTypeDescription
		{
			get { return ""; }
		}

		/// <summary>
		/// Gets the name of the table.
		/// </summary>
		/// <value>The name of the table.</value>
		public override string TableName
		{
			get { return "wf_events"; }
		}

		/// <summary>
		/// Gets the allowed child types.
		/// </summary>
		/// <value>The allowed child types.</value>
		public override List<ItemType> AllowedChildTypes
		{
			get { return null; }
		}

		/// <summary>
		/// Gets the icon.
		/// </summary>
		/// <returns></returns>
		public override System.Drawing.Icon GetIcon()
		{
			Bitmap bmp = new Bitmap(this.Image);
			bmp.MakeTransparent(Color.Magenta);
			return Icon.FromHandle(bmp.GetHicon());
		}

		/// <summary>
		/// Internally delete the item.
		/// </summary>
		/// <returns></returns>
		internal override bool DeleteInternal()
		{
			return base.DeleteInternal();
		}

		/// <summary>
		/// Internal delete the item from the database.
		/// </summary>
		/// <param name="bAsk">if set to <c>true</c> [b ask].</param>
		/// <returns></returns>
		internal override bool DeleteFromDBInternal(bool bAsk)
		{
			return base.DeleteFromDBInternal(bAsk);
		}
		#endregion

		#region Public Members

		#region Properties

		#region Business Object
		/// <summary>
		/// Gets or sets the business object ID.
		/// </summary>
		/// <value>The business object ID.</value>
		public int BusinessObjectID
		{
			get { return getInt("wf_event_bobj_id", -1); }
			set { setValue("BusinessObjectID", "wf_event_bobj_id", value); }
		}
		/// <summary>
		/// Gets or sets the business object.
		/// </summary>
		/// <value>The business object.</value>
		public BusinessObject BusinessObject
		{
			get
			{
				return this.RepositoryService.GetItem<BusinessObject>(this.BusinessObjectID);
			}
			set
			{
				if ( value != null )
					this.BusinessObjectID = value.ID;
				else
					this.BusinessObjectID = -1;
			}
		}
		/// <summary>
		/// Gets the name of the business object.
		/// </summary>
		/// <value>The name of the business object.</value>
		public string BusinessObjectName
		{
			get
			{
				BusinessObject bo = this.BusinessObject;
				return ( bo == null ? "" : bo.Name );
			}
		}
		#endregion

		#region IsStart
		/// <summary>
		/// Gets or sets a value indicating whether this instance is start.
		/// </summary>
		/// <value><c>true</c> if this instance is start; otherwise, <c>false</c>.</value>
		public bool IsStart
		{
			get { return getBool("wf_event_is_start", false); }
			set { setValue("IsStart", "wf_event_is_start", value); }
		}
		#endregion

		#region Workflow
		/// <summary>
		/// Gets or sets the workflow ID.
		/// </summary>
		/// <value>The workflow ID.</value>
		public int WorkflowID
		{
			get { return getInt("workflow_id", -1); }
			set { setValue("WorkflowID", "workflow_id", value); }
		}
		/// <summary>
		/// Gets or sets the workflow.
		/// </summary>
		/// <value>The workflow.</value>
		public Workflow Workflow
		{
			get
			{
				if ( this.WorkflowID > 0 ) {
					return this.RepositoryService.GetItem<OpenComposite.EII.Repository.Workflow>(this.WorkflowID);
				} else {
					return null;
				}
			}
			set { this.WorkflowID = ( value == null ? -1 : value.ID ); }
		}
		#endregion

		#region Mashup Control
		private Workflow.MashupControl _mashupCtrl = null;
		/// <summary>
		/// Gets or sets the mashup control.
		/// </summary>
		/// <value>The mashup control.</value>
		public Workflow.MashupControl MashupControl
		{
			get
			{
				if ( _mashupCtrl == null ) {
					_mashupCtrl = getXmlSerializedObject<Workflow.MashupControl>("wf_event_ntext");
				}
				return _mashupCtrl;
			}
			set
			{
				_mashupCtrl = value;
				setXmlSerializedObject("MashupControl", "wf_event_ntext", value);
			}
		}
		#endregion

		#region ExtendedProperties
		private WFEventProperties _properties = null;
		/// <summary>
		/// Gets the extended properties.
		/// </summary>
		/// <value>The extended properties.</value>
		public WFEventProperties ExtendedProperties
		{
			get
			{
				if ( _properties == null ) {
					_properties = getXmlSerializedObject<WFEventProperties>("wf_event_properties");
					if ( _properties == null )
						_properties = new WFEventProperties();
				}
				return _properties;
			}
		}

		#endregion

		#region Properties for Databinding
		/// <summary>
		/// Gets a value indicating whether this instance is initialize correlation.
		/// </summary>
		/// <value>
		/// 	<c>true</c> if this instance is initialize correlation; otherwise, <c>false</c>.
		/// </value>
		public bool IsInitializeCorrelation
		{
			get { return this.ExtendedProperties.IsInitializeCorrelation; }
		}
		/// <summary>
		/// Gets the correlation aliases string.
		/// </summary>
		/// <value>The correlation aliases string.</value>
		public string CorrelationAliasesString
		{
			get { return this.ExtendedProperties.CorrelationAliasesString; }
		}
		#endregion

		#endregion

		#region Methods

		/// <summary>
		/// Sets the drag drop data object.
		/// </summary>
		/// <param name="dataObj">The data object.</param>
		public override void SetDragDropDataObject(IDataObject dataObj)
		{
			base.SetDragDropDataObject(dataObj);

			ToolboxItem ti = OpenComposite.EII.Designer.Workflow.ToolboxService.GetToolboxItem(
								typeof(OpenComposite.Workflow.LogicalInputActivity));
			OpenComposite.Workflow.LogicalInputActivityToolboxItem ati = ti as OpenComposite.Workflow.LogicalInputActivityToolboxItem;
			if ( ati != null ) {
				ati.InitializeLogicalInputActivity +=
					new EventHandler<OpenComposite.Workflow.InitializeLogicalInputActivityEventArgs>(
						ati_InitializeLogicalInputActivity);
			}
			dataObj.SetData(typeof(ToolboxItem), ti);
		}
		private void ati_InitializeLogicalInputActivity(object sender,
			OpenComposite.Workflow.InitializeLogicalInputActivityEventArgs e)
		{
			OpenComposite.Workflow.LogicalInputActivityToolboxItem ati = sender as OpenComposite.Workflow.LogicalInputActivityToolboxItem;
			if ( e.LogicalInputActivity != null ) {
				OpenComposite.EII.Designer.Workflow.WorkflowLoader wfl = null;
				if ( e.LogicalInputActivity.Site != null ) {
					wfl = e.LogicalInputActivity.Site.GetService(typeof(System.Workflow.ComponentModel.Design.WorkflowDesignerLoader)) as OpenComposite.EII.Designer.Workflow.WorkflowLoader;
				}
				LogicalActivity logact;
				if ( e.LogicalInputActivity.LogicalActivityId == 0 && ati.Tag is int )
					logact = this.AssignLogicalActivity((int)ati.Tag);
				else
					logact = this.AssignLogicalActivity(e.LogicalInputActivity.LogicalActivityId);
				e.LogicalInputActivity.LogicalActivityId = logact.ID;
				e.LogicalInputActivity.LogicalActivityName = logact.Name;

				logact.LogicalActivityType = LogicalActivityType.LogicalInput;

				e.LogicalInputActivity.HasOutputObject = ( this.BusinessObject != null );
				if ( this.BusinessObject != null ) {
					e.LogicalInputActivity.SetValue(OutputVariableNameExtenderProvider.OutputVarNameProperty,
						string.Format("{0}_{1}", this.Name, this.BusinessObjectName));
				}

				Helpers.SetActivityProperty(e.LogicalInputActivity, "Name", logact.Name);
				if ( wfl != null ) {
					Helpers.SetActivityProperty(e.LogicalInputActivity, "InterfaceType", wfl.ExternalDataExchangeInterfaceType);
					Helpers.SetActivityProperty(e.LogicalInputActivity, "EventName", this.Name);
				}
				if ( ati != null ) {
					ati.Tag = logact.ID;
				}
			}
		}

		/// <summary>
		/// Gets the assigned logical activities.
		/// </summary>
		/// <returns></returns>
		public BindingListEx<LogicalActivity> GetAssignedLogicalActivities()
		{
			return Global.Data.GetLogicalActivitiesByWorkflowEvent(this.ID);
		}
		/// <summary>
		/// Assigns the logical activity.
		/// </summary>
		/// <param name="idLogicalActivity">The id logical activity.</param>
		/// <returns></returns>
		public LogicalActivity AssignLogicalActivity(int idLogicalActivity)
		{
			RepositoryService repSvc = (RepositoryService)this.GetService(typeof(RepositoryService));
			if ( repSvc == null )
				throw new NullReferenceException("RepositoryService not available.");

			bool bSC;
			LogicalActivity logact = null;
			if ( idLogicalActivity > 0 ) {
				logact = repSvc.GetItem(ItemType.LogicalActivity, idLogicalActivity, true) as LogicalActivity;
				if ( logact.WorkflowEventID != this.ID ) {
					setLogActValues(logact);
				}
			} else {
				logact = repSvc.GetItem(ItemType.LogicalActivity, true,
					Global.Status.CurrentRepositoryId, false, false, out bSC) as LogicalActivity;
				setLogActValues(logact);
			}
			return logact;
		}
		private void setLogActValues(LogicalActivity logact)
		{
			logact.BeginEdit();
			try {
				logact.WorkflowEventID = this.ID;
				logact.Name = this.Name;
				logact.Description = this.Description;
				logact.NText = this.NText;
				logact.LogicalActivityType = LogicalActivityType.LogicalInput;
			} finally {
				logact.EndEdit(true);
			}
		}

		/// <summary>
		/// Saves this instance.
		/// </summary>
		/// <returns></returns>
		public override bool Save()
		{
			if ( _properties != null ) {
				setXmlSerializedObject("ExtendedProperties", "wf_event_properties", _properties);
			}
			return base.Save();
		}
		/// <summary>
		/// Deletes this instance.
		/// </summary>
		/// <param name="bAsk">if set to <c>true</c> show a message to ask for deleting.</param>
		/// <returns></returns>
		public override bool Delete(bool bAsk)
		{
			if ( !bAsk || MessageBox.Show(this.DeleteQuestion, this.RepositoryItemType.ToString(),
				 MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes ) {
				BindingListEx<LogicalActivity> logacts = this.GetAssignedLogicalActivities();
				foreach ( LogicalActivity la in logacts ) {
					la.BeginEdit();
					la.WorkflowEventID = -1;
					la.EndEdit(true);
					la.Delete(false);
				}
				return base.Delete(false);
			} else {
				return false;
			}
		}

		/// <summary>
		/// Copies this instance.
		/// </summary>
		/// <param name="deep"><c>true</c> to recursively copy the item and all subitems;
		/// <c>false</c> to copy only the item itself.</param>
		/// <returns>The copied item.</returns>
		public override IRepositoryItem Copy(bool deep)
		{
			WorkflowEvent copy = new WorkflowEvent(this, true);
			this.CopyDataRowToTarget(copy);
			return copy;
		}
		internal WorkflowEvent CopyInternal(bool deep, bool createCopyOfName)
		{
			WorkflowEvent copy = new WorkflowEvent(this, true);
			this.CopyDataRowToTarget(copy, createCopyOfName);
			return copy;
		}
		#endregion

		#endregion

		#region IWorkflowInterfaceItem Members

		/// <summary>
		/// Gets the IO types.
		/// </summary>
		/// <value>The IO types.</value>
		public string IOTypes
		{
			get { return this.BusinessObjectName; }
		}

		/// <summary>
		/// Gets the summary.
		/// </summary>
		/// <value>The summary.</value>
		public string Summary
		{
			get { return this.Description.Replace(Environment.NewLine, ""); }
		}

		#endregion

		#region Class: WFEventProperties
		public class WFEventProperties : WorkflowInterfaceItemProperties
		{
		}
		#endregion

		#region IEquatable<WorkflowEvent> Members

		/// <summary>
		/// Indicates whether the current object is equal to another object of the same type.
		/// </summary>
		/// <param name="other">An object to compare with this object.</param>
		/// <returns>
		/// true if the current object is equal to the <paramref name="other"/> parameter; otherwise, false.
		/// </returns>
		public bool Equals(WorkflowEvent other)
		{
			if ( other == null ) return false;
			if ( other.ID == this.ID ) return true;
			return false;
		}

		#endregion
	}
	#endregion

	#endregion

	#region Workflow Field Classes

	#region Class: WorkflowFieldCollection

	public class WorkflowFieldCollection : BindingListEx<WorkflowField>
	{
		/// <summary>
		/// Removes all elements from the collection.
		/// </summary>
		protected override void ClearItems()
		{
			foreach ( WorkflowField item in this.Items ) {
				item.Delete(false);
			}
			base.ClearItems();
		}
		/// <summary>
		/// Removes the item at the specified index.
		/// </summary>
		/// <param name="index">The zero-based index of the item to remove.</param>
		/// <exception cref="T:System.NotSupportedException">
		/// You are removing a newly added item and <see cref="P:System.ComponentModel.IBindingList.AllowRemove"/> is set to false.
		/// </exception>
		protected override void RemoveItem(int index)
		{
			this.Items[index].Delete(false);
			base.RemoveItem(index);
		}
		/// <summary>
		/// Replaces the item at the specified index with the specified item.
		/// </summary>
		/// <param name="index">The zero-based index of the item to replace.</param>
		/// <param name="item">The new value for the item at the specified index. The value can be null for reference types.</param>
		/// <exception cref="T:System.ArgumentOutOfRangeException">
		/// 	<paramref name="index"/> is less than zero.
		/// -or-
		/// <paramref name="index"/> is greater than <see cref="P:System.Collections.ObjectModel.Collection`1.Count"/>.
		/// </exception>
		protected override void SetItem(int index, WorkflowField item)
		{
			this.Items[index].Delete(false);
			base.SetItem(index, item);
		}
	}
	#endregion

	#region Class: WorkflowField
	[RepositoryItem(ItemType.Workflow_Field, "wf_fields", "wf_field_id")]
	public class WorkflowField : RepositoryItemBaseEx, IWorkflowInterfaceItem, IEquatable<WorkflowField>
	{
		#region Initialization
		/// <summary>
		/// Initializes a new instance of the <see cref="WorkflowField"/> class.
		/// </summary>
		/// <param name="serviceProvider">The service provider.</param>
		/// <param name="bCreateNew">if set to <c>true</c> [b create new].</param>
		public WorkflowField(IServiceProvider serviceProvider, bool bCreateNew)
			: base("wf_field_id", "wf_field_nm", "wf_field_desc", "wf_field_ntext", "<New Field>")
		{
			if ( bCreateNew )
				this.CreateNew();

			InitializeServiceProvider(serviceProvider);
		}
		#endregion

		#region RepositoryItemBase Members
		/// <summary>
		/// Gets the image key.
		/// </summary>
		/// <value>The image key.</value>
		public override string ImageKey
		{
			get { return "field"; }
		}

		/// <summary>
		/// Gets the selected image key.
		/// </summary>
		/// <value>The selected image key.</value>
		public override string SelectedImageKey
		{
			get { return this.ImageKey; }
		}

		/// <summary>
		/// Gets the image.
		/// </summary>
		/// <value>The image.</value>
		public override System.Drawing.Image Image
		{
			get { return OpenComposite.Repository.Properties.Resources.png_field; }
		}

		/// <summary>
		/// Gets the selected image.
		/// </summary>
		/// <value>The selected image.</value>
		public override System.Drawing.Image SelectedImage
		{
			get { return this.Image; }
		}

		/// <summary>
		/// Gets the type of the repository item.
		/// </summary>
		/// <value>The type of the repository item.</value>
		public override ItemType RepositoryItemType
		{
			get { return ItemType.Workflow_Field; }
		}

		/// <summary>
		/// Gets the name of the repository item type.
		/// </summary>
		/// <value>The name of the repository item type.</value>
		public override string RepositoryItemTypeName
		{
			get { return "Workflow Field"; }
		}

		/// <summary>
		/// Gets the repository item type description.
		/// </summary>
		/// <value>The repository item type description.</value>
		public override string RepositoryItemTypeDescription
		{
			get { return ""; }
		}

		/// <summary>
		/// Gets the name of the table.
		/// </summary>
		/// <value>The name of the table.</value>
		public override string TableName
		{
			get { return "wf_fields"; }
		}

		/// <summary>
		/// Gets the allowed child types.
		/// </summary>
		/// <value>The allowed child types.</value>
		public override List<ItemType> AllowedChildTypes
		{
			get { return null; }
		}

		/// <summary>
		/// Gets the icon.
		/// </summary>
		/// <returns></returns>
		public override System.Drawing.Icon GetIcon()
		{
			Bitmap bmp = new Bitmap(this.Image);
			bmp.MakeTransparent(Color.Magenta);
			return Icon.FromHandle(bmp.GetHicon());
		}

		/// <summary>
		/// Saves this instance.
		/// </summary>
		/// <returns></returns>
		public override bool Save()
		{
			BusinessObject bo = GetContainerBusinessObject();
			if ( bo != null ) {
				bo.BeginEdit();
				bo.Name = this.Name;
				bo.Description = this.Description;
				bo.DomainId = Global.Status.CurrentDomainId;
				bo.OrganizationId = Global.CurrentUser.OrganizationID;
				bo.EndEdit(true);
			}
			return base.Save();
		}
		#endregion

		#region Public Members

		#region Business Object
		/// <summary>
		/// Gets or sets the business object ID.
		/// </summary>
		/// <value>The business object ID.</value>
		public int BusinessObjectID
		{
			get { return getInt("wf_field_bobj_id", -1); }
			set { setValue("BusinessObjectID", "wf_field_bobj_id", value); }
		}
		/// <summary>
		/// Gets or sets the business object.
		/// </summary>
		/// <value>The business object.</value>
		public BusinessObject BusinessObject
		{
			get { return this.RepositoryService.GetItem<BusinessObject>(this.BusinessObjectID); }
			set
			{
				if ( value != null )
					this.BusinessObjectID = value.ID;
				else
					this.BusinessObjectID = -1;
			}
		}
		#endregion

		/// <summary>
		/// Gets or sets the type of the data.
		/// </summary>
		/// <value>The type of the data.</value>
		public string DataType
		{
			get
			{
				BusinessObject bo = this.BusinessObject;
				if ( bo != null )
					return bo.Name;
				else
					return getString("wf_field_datatype", null);
			}
			set
			{
				if ( !string.IsNullOrEmpty(value) )
					this.BusinessObject = null;
				setValue("DataType", "wf_field_datatype", value);
			}
		}

		/// <summary>
		/// Gets or sets the workflow.
		/// </summary>
		/// <value>The workflow.</value>
		public Workflow Workflow
		{
			get
			{
				if ( this.WorkflowID > 0 ) {
					return this.RepositoryService.GetItem<OpenComposite.EII.Repository.Workflow>(this.WorkflowID);
				} else {
					return null;
				}
			}
			set { this.WorkflowID = ( value == null ? -1 : value.ID ); }
		}

		/// <summary>
		/// Gets or sets the workflow ID.
		/// </summary>
		/// <value>The workflow ID.</value>
		public int WorkflowID
		{
			get { return getInt("workflow_id", -1); }
			set { setValue("WorkflowID", "workflow_id", value); }
		}

		/// <summary>
		/// Creates the container business object.
		/// </summary>
		public void CreateContainerBusinessObject()
		{
			if ( GetContainerBusinessObject() != null ) return;

			IRepositoryItem parentItem = null;
			BusinessObject bo = this.RepositoryService.GetNewItem<OpenComposite.EII.Repository.BusinessObject>(
									false, ref parentItem);
			if ( bo != null ) {
				bo.BeginEdit();
				bo.Name = this.Name;
				bo.Description = this.Description;
				bo.DomainId = Global.Status.CurrentDomainId;
				bo.OrganizationId = Global.CurrentUser.OrganizationID;
				bo.WorkflowFieldID = this.ID;
				bo.EndEdit(true);
			}
		}
		/// <summary>
		/// Gets the container business object.
		/// </summary>
		/// <returns></returns>
		public BusinessObject GetContainerBusinessObject()
		{
			return Global.Data.GetContainerBusinessObjectOfWorkflowField(this.ID);
		}

		/// <summary>
		/// Copies this instance.
		/// </summary>
		/// <param name="deep"><c>true</c> to recursively copy the item and all subitems;
		/// <c>false</c> to copy only the item itself.</param>
		/// <returns>A copy of this instance.</returns>
		public override IRepositoryItem Copy(bool deep)
		{
			WorkflowField copy = new WorkflowField(this, true);
			this.CopyDataRowToTarget(copy);
			return copy;
		}
		/// <summary>
		/// Copies this instance.
		/// </summary>
		/// <param name="deep">if set to <c>true</c> creates a deep copy.</param>
		/// <param name="createCopyOfName">if set to <c>true</c> the name of the new item starts with "CopyOf".</param>
		/// <returns>A copy of this instance</returns>
		internal WorkflowField CopyInternal(bool deep, bool createCopyOfName)
		{
			WorkflowField copy = new WorkflowField(this, true);
			this.CopyDataRowToTarget(copy, createCopyOfName);
			return copy;
		}
		#endregion

		#region IWorkflowInterfaceItem Members

		/// <summary>
		/// Gets the IO types.
		/// </summary>
		/// <value>The IO types.</value>
		public string IOTypes
		{
			get { return this.DataType; }
		}
		/// <summary>
		/// Gets the summary.
		/// </summary>
		/// <value>The summary.</value>
		public string Summary
		{
			get { return this.Description.Replace(Environment.NewLine, ""); }
		}

		#endregion

		#region IEquatable<WorkflowField> Members

		/// <summary>
		/// Indicates whether the current object is equal to another object of the same type.
		/// </summary>
		/// <param name="other">An object to compare with this object.</param>
		/// <returns>
		/// true if the current object is equal to the <paramref name="other"/> parameter; otherwise, false.
		/// </returns>
		public bool Equals(WorkflowField other)
		{
			if ( other == null ) return false;
			if ( other.ID == this.ID ) return true;
			return false;
		}

		#endregion
	}
	#endregion

	#endregion

	#region Interface: IWorkflowInterfaceItem
	internal interface IWorkflowInterfaceItem
	{
		/// <summary>
		/// Gets the image.
		/// </summary>
		/// <value>The image.</value>
		System.Drawing.Image Image { get; }
		/// <summary>
		/// Gets the name.
		/// </summary>
		/// <value>The name.</value>
		string Name { get; }
		/// <summary>
		/// Gets the IO types.
		/// </summary>
		/// <value>The IO types.</value>
		string IOTypes { get; }
		/// <summary>
		/// Gets the summary.
		/// </summary>
		/// <value>The summary.</value>
		string Summary { get; }
	}
	#endregion

	#region Class: CorrelationAlias
	[TypeConverter(typeof(ExpandableObjectConverter))]
	public class CorrelationAlias
	{
		#region Initialization
		/// <summary>
		/// Initializes a new instance of the <see cref="CorrelationAlias"/> class.
		/// </summary>
		public CorrelationAlias()
		{
			_parameterName = "";
			_path = "";
		}
		/// <summary>
		/// Initializes a new instance of the <see cref="CorrelationAlias"/> class.
		/// </summary>
		/// <param name="parametername">The parametername.</param>
		public CorrelationAlias(string parametername)
			: this()
		{
			_parameterName = parametername;
		}
		#endregion

		#region Public Members

		#region Properties
		/// <summary>
		/// Gets or sets the name of the parameter.
		/// </summary>
		/// <value>The name of the parameter.</value>
		public string ParameterName
		{
			get { return _parameterName; }
			set { _parameterName = value; }
		}
		/// <summary>
		/// Gets or sets the path.
		/// </summary>
		/// <value>The path.</value>
		public string Path
		{
			get { return _path; }
			set { _path = value; }
		}
		#endregion

		#region Methods
		/// <summary>
		/// Returns a <see cref="System.String"/> that represents this instance.
		/// </summary>
		/// <returns>
		/// A <see cref="System.String"/> that represents this instance.
		/// </returns>
		public override string ToString()
		{
			return string.Format("{0}: {1}", this.ParameterName, this.Path);
		}
		#endregion

		#endregion

		#region Private Members

		#region Fields
		private string _parameterName;
		private string _path;
		#endregion

		#endregion

	}
	#endregion

	#region Class: WorkflowInterfaceItemProperties
	[TypeConverter(typeof(ExpandableObjectConverter))]
	public abstract class WorkflowInterfaceItemProperties
	{
		#region Initialization
		/// <summary>
		/// Initializes a new instance of the <see cref="WorkflowInterfaceItemProperties"/> class.
		/// </summary>
		public WorkflowInterfaceItemProperties()
		{
		}
		#endregion

		#region Public Members

		#region Properties
		/// <summary>
		/// Gets or sets a value indicating whether this instance is initialize correlation.
		/// </summary>
		/// <value>
		/// 	<c>true</c> if this instance is initialize correlation; otherwise, <c>false</c>.
		/// </value>
		public bool IsInitializeCorrelation
		{
			get { return _isInitializeCorrelation; }
			set { _isInitializeCorrelation = value; }
		}

		/// <summary>
		/// Gets the correlation aliases string.
		/// </summary>
		/// <value>The correlation aliases string.</value>
		public string CorrelationAliasesString
		{
			get
			{
				string[] strs = new string[this.CorrelationAliases.Count];
				for ( int i = 0; i < this.CorrelationAliases.Count; i++ ) {
					strs[i] = this.CorrelationAliases[i].ToString();
				}
				return string.Join("; ", strs);
			}
		}
		/// <summary>
		/// Gets the correlation aliases.
		/// </summary>
		/// <value>The correlation aliases.</value>
		[XmlIgnore]
		public List<CorrelationAlias> CorrelationAliases
		{
			get { return _correlationAliases; }
		}
		/// <summary>
		/// Gets or sets the correlation aliases array.
		/// </summary>
		/// <value>The correlation aliases array.</value>
		[EditorBrowsable(EditorBrowsableState.Never), Browsable(false)]
		public CorrelationAlias[] CorrelationAliasesArray
		{
			get { return _correlationAliases.ToArray(); }
			set
			{
				_correlationAliases.Clear();
				_correlationAliases.AddRange(value);
			}
		}
		#endregion

		#endregion

		#region Private Members

		#region Fields
		private bool _isInitializeCorrelation = false;
		private List<CorrelationAlias> _correlationAliases = new List<CorrelationAlias>();
		#endregion

		#endregion
	}
	#endregion

}
